/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_TOPIC_H_
#define _DAL_TOPIC_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "dal/ret_type.h"
#include "dal/base_type.h"
#include "dal/status.h"
#include "dal/dds_entity.h"

#ifndef _DAL_DOMAIN_PARTICIPANT_H_
typedef struct dal_domain_participant_s dal_domain_participant_t;
#endif

// TYPE SUPPORT
typedef struct dal_type_support_s
{
    void* handle_;
    char* type_name_;
    const void* type_support_impl_;
} dal_type_support_t;

dal_ret_t dal_type_support_register_type(dal_type_support_t* ts,
                                         dal_domain_participant_t* participant,
                                         const char* type_name);

dal_type_support_t* dal_create_type_support(void* type);
dal_ret_t dal_delete_type_support(dal_type_support_t* ts);
const char* dal_type_support_get_type_name(dal_type_support_t* ts);

// User must init callbacks' memory to 0 before using.
typedef struct dal_topic_listener_callbacks_s
{
    void (*on_inconsistent_topic)(dal_topic_t*, dal_inconsistent_topic_status_t*, void*);

    // offer callbacks the ability to access external resources, like binding
    // parameters;
    void* data_;
} dal_topic_listener_callbacks_t;


dal_topic_listener_t* dal_create_topic_listener(dal_topic_listener_callbacks_t callbacks);
dal_ret_t dal_delete_topic_listener(dal_topic_listener_t* listener);

dal_ret_t dal_topic_enable(dal_topic_t* topic);
dal_status_condition dal_topic_get_statuscondition(dal_topic_t* topic);
dal_status_mask_t dal_topic_get_status_changes(dal_topic_t* topic);
dal_instance_handle_t dal_topic_get_instance_handle(dal_topic_t* topic);
dal_ret_t dal_topic_set_qos(dal_topic_t* topic, dal_topic_qos_t qos);
dal_ret_t dal_topic_get_qos(dal_topic_t* topic, dal_topic_qos_t* qos);
dal_ret_t
dal_topic_set_listener(dal_topic_t* topic, dal_topic_listener_t* listener, dal_status_mask_t mask);
dal_topic_listener_t* dal_topic_get_listener(dal_topic_t* topic);
// Access the status
dal_ret_t dal_topic_get_inconsistent_topic_status(dal_topic_t* topic,
                                                  dal_inconsistent_topic_status_t* a_status);

// interface ContentFilteredTopic : TopicDescription
// {
//     string get_filter_expression();
//     dal_ret_t get_expression_parameters(
//         inout StringSeq);
//     dal_ret_t set_expression_parameters(
//         in StringSeq expression_parameters);
//     Topic get_related_topic();
// };
// interface MultiTopic : TopicDescription
// {
//     string get_subscription_expression();
//     dal_ret_t get_expression_parameters(
//         inout StringSeq);
//     dal_ret_t set_expression_parameters(
//         in StringSeq expression_parameters);
// };
// ----------------------------------------------------------------------

#ifdef __cplusplus
}
#endif

#endif  // _DAL_TOPIC_H_
